<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新增或编辑页面</title>
</head>

<body>
    <table>
        <tr>
            <td>
                <label for=""> 商品名称：</label>
            </td>

            <td>
                <input type="text" name="name" id="" autocomplete="off">
            </td>
        </tr>
        <tr>
            <td>
                <label for=""> 库存</label>
            </td>
            <td>
                <input type="text" name="stock" id="">
            </td>
        </tr>
        <tr>
            <td>
                <label for=""> 价格：</label>
            </td>
            <td>
                <input type="text" name="price" id="">
            </td>
        </tr>
        <tr>
            <td>
                <label for=""> 品牌商：</label>
            </td>
            <td>
                <input type="text" name="pps" id="">
            </td>
        </tr>
        <tr>
            <td><input type="button" value="保存" onclick="Save()"></td>
            <td><input type="button" value="取消" onclick="QuXiao()"></td>
        </tr>
    </table>


    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src="./js/index.js"></script>


    <!--  //跳转到编辑页面 需要预加载 给input赋值 -->
    <script>
        let reqiestPut_id = location.search.split('=')[1];
        if (reqiestPut_id != undefined) {
            //这是来获取btn_edit 编辑按钮 通过url传的id
            //console.log(reqiestPut_id);
            //url的id发一个请求 通过后端拿到这个id其余的value  然后给input赋值
            $.get(`http://localhost:8000/product${reqiestPut_id}`, (data) => {
                console.log(data);
                let put_name = $('[name=name]').val(`${data[0].product}`);
                let put_stock = $('[name=stock]').val(`${data[0].stock}`);
                let put_price = $('[name=price]').val(`${data[0].price}`);
                let put_pps = $('[name=pps]').val(`${data[0].pps}`);

            })
        }


    </script>




</body>

</html>